WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
singleton.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19#pragma once
20
21#include <memory>
22
23namespace wolf
24{
25namespace internal
26{
31template <class T>
33{
34 using SingletonOPtr = std::unique_ptr<T>;
35
36 public:
37 template <typename... Args>
38 static T& get(Args&&... args)
39 {
40 static SingletonOPtr instance_(new T(std::forward<Args>(args)...));
41
42 return *instance_;
43 }
44
45 constexpr Singleton(const Singleton&) = delete;
46 constexpr Singleton(const Singleton&&) = delete;
47
48 constexpr Singleton& operator=(const Singleton&) const = delete;
49 constexpr Singleton& operator=(const Singleton&&) const = delete;
50
51 protected:
52 constexpr Singleton() = default;
53 virtual ~Singleton() = default;
54};
55
56} // namespace internal
57} // namespace wolf
A thread-safer (?) Singleton implementation with argument forwarding.
Definition: singleton.h:33
constexpr Singleton & operator=(const Singleton &) const =delete
constexpr Singleton(const Singleton &)=delete
constexpr Singleton & operator=(const Singleton &&) const =delete
static T & get(Args &&... args)
Definition: singleton.h:38
constexpr Singleton(const Singleton &&)=delete
constexpr Singleton()=default
virtual ~Singleton()=default
Definition: capture_base.h:23